
/**
 * 货物类别列表返回数据实体
 */
interface GoodsTypeListItemResponse {
    /**
     * 标识符
     */
    id: string;
    /**
     * 序号
     */
    index: number;
    /**
     * 分类名称
     */
    name: string;
    /**
     * 添加时间
     */
    createTime: string
}

/**
 * 货物类别详情返回数据实体
 */
interface GoodsTypeDetailResponse extends BaseResponse {

    /**
     * 企业公司编号
     */
    enterpriseCompanyId: string;
    /**
     * 货物类别名称
     */
    name: string;
    /**
     * 备注
     */
    remarks: string
}

/**
 *货物类别服务 
 */
interface IGoodsTypeService {
    /**
     * 获取货物类别列表
     * v1.0
     * @param enterpriseid 企业公司编号
     * @param name 类别名称
     * @param skip 跳过项数
     * @param count 获取项数
     */
    getList(enterpriseid: string, name: string,  skip: number, count: number): ng.IHttpPromise<ListResponse<GoodsTypeListItemResponse>>;

    /**
     * 获取货物类别详细
     * v1.0
     * @param id 需要获取的货物类别编号
     */
    getDetail(id: string): ng.IHttpPromise<GoodsTypeDetailResponse>;

    /**
     * 编辑货物类别
     * v1.0
     * @param id 需要编辑的货物类别编号
     * @param enterpriseCompanyId 企业公司编号
     * @param name 货物类别名称
     * @param remarks 备注
     */
    edit(id: string, enterpriseCompanyId: string, name: string, remarks:string): ng.IHttpPromise<BaseResponse>;

    /**
     * 添加货物类别
     * v1.0
     * @param enterpriseCompanyId 企业公司编号
     * @param name 货物类别名称
     * @param remarks 备注
     */
    add(enterpriseCompanyId: string, name: string,remarks:string): ng.IHttpPromise<BaseResponse>;

     /**
      * 删除货物类别
      * v1.0
      * @param id 需要删除的货物类别编号
      */
    delete(id:string):ng.IHttpPromise<BaseResponse>;
}

class goodsTypeService implements IGoodsTypeService {
    constructor(private http: ng.IHttpService, private route: routeService) {
    }

    getList(enterpriseid: string, name: string,  skip: number, count: number): ng.IHttpPromise<ListResponse<GoodsTypeListItemResponse>> {
        return this.http<ListResponse<GoodsTypeListItemResponse>>({
            method: "GET",
            url: this.route.getUrl("goodsType?enterpriseid={{enterpriseid}}&name={{name}}&skip={{skip}}&count={{count}}", {
                "enterpriseid": enterpriseid,
                "name": name,
                "skip": skip,
                "count": count
            })
        });
    }

    getDetail(id: string): ng.IHttpPromise<GoodsTypeDetailResponse> {
        return this.http<GoodsTypeDetailResponse>({
            method: "GET",
            url: this.route.getUrl("goodsType/{{id}}", {
                id: id
            })
        });
    }

    edit(id: string, enterpriseCompanyId: string, name: string, remarks:string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "PUT",
            url: this.route.getUrl("goodsType/{{id}}", {
                id: id
            }),
            data: {
                enterpriseCompanyId: enterpriseCompanyId,
                name: name,
                remarks:  remarks
            }
        });
    }

    add(enterpriseCompanyId: string, name: string,remarks:string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "POST",
            url: this.route.getUrl("goodsType"),
            data: {
                enterpriseCompanyId: enterpriseCompanyId,
                name: name,
                remarks: remarks
            }
        });
    }

      delete(id: string): ng.IHttpPromise<BaseResponse> {
              return this.http<BaseResponse>({
                   method: "DELETE",
                   url: this.route.getUrl("goodsType/{{id}}", {
                   id: id
                 })
             });
         }

}

angular.module("goodsTypeService",[]).service("goodsTypeService",['$http','routeService',goodsTypeService]);